<template>
	<view class="wrap">
		<!-- 修改密码界面 -->
		<u-input v-model="oldPassword" :type="type" :border="border" placeholder="请输入旧密码" />
		<u-input v-model="newPassword" :type="type" :border="border" :password-icon="passwordIcon" placeholder="请输入新密码" />
		<u-input v-model="newPasswordConfig" :type="type" :border="border" :password-icon="passwordIcon" placeholder="请输入新密码" />
		<u-button @click="modifyPassword()" :disabled="passWordRight==true">确认修改</u-button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				oldPassword: '',
				newPassword: '',
				newPasswordConfig: '',
				type: 'password',
				passwordIcon: true,
				border: true,
			}
		},
		methods: {
			async modifyPassword() {
				const params = {
					old_password: this.oldPassword,
					password: this.newPassword,
					password_confirmation: this.newPasswordConfig
				}
				await this.$u.post('/api/auth/password/update', params).then(res => {
					console.log(res)
					// 判断状态码
					if (res.statusCode === 204) {
						this.$u.toast('密码修改成功');
						uni.$u.route({
							type:'reLaunch',
							url: '/pages/me/me'
						})
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		computed:{
			passWordRight(){
				return !this.oldPassword || !this.newPassword || !this.newPasswordConfig
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 40rpx;
	}

	.u-size-default {
		margin-top: 100rpx;
		border: none;
		background-color: #2979ff;
		color: white;
		box-shadow: rgba($color: #000000, $alpha: 1.0);
	}
	.u-input{
		margin-bottom: 40rpx;
	}
</style>
